package com.daotingli.backendprograms.Service.Admin.Tag;

import com.daotingli.backendprograms.Repository.Admin.Tag.TagRepository;
import com.daotingli.backendprograms.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class TagService {

    @Autowired
    private TagRepository tagRepository;

    public Result getTag() {
        return Result.success(tagRepository.getAllTag());
    }

    public Result addTag(String type) {
        Map<String, Object> result = tagRepository.addTag(type);
        if ("success".equals(result.get("status"))) {
            return Result.success();
        } else {
            return Result.error((String) result.get("message"));
        }
    }

    public Result deleteTag(Integer id) {
        Map<String, Object> result = tagRepository.deleteTag(id);
        if ("success".equals(result.get("status"))) {
            return Result.success();
        } else {
            return Result.error((String) result.get("message"));
        }
    }

    public Result updateTag(Integer id, String type) {
        Map<String, Object> result = tagRepository.updateTag(id, type);
        if ("success".equals(result.get("status"))) {
            return Result.success();
        } else {
            return Result.error((String) result.get("message"));
        }
    }
}
